package day07demo;

import java.util.Random;
import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            String code = code(5);
            System.out.println(code);
            System.out.println("请输入验证码");
            String inputCode = sc.next();
            if (code.equalsIgnoreCase(inputCode)){
                System.out.println(true);
                break;

            }else {
                System.out.println(false);
                continue;
            }
        }
    }
    public static String code(int len) {
        char[] arr = new char[62];
        int a = 97;
        int A = 65;
       int zero = 48;
        for (int i = 0; i < arr.length; i++) {
            if (i < 26) {
                arr[i] = (char) a;
                a++;
            }else if (i>=26&& i<52){
                arr[i] = (char) A;
                A++;
            }else {
                arr[i] = (char)zero;
                zero++;
            }
        }
        StringBuilder sb = new StringBuilder();
        Random r = new Random();
        for (int i = 0; i < len; i++) {
            int randomNumber = r.nextInt(62);
            sb.append(arr[randomNumber]);
        }
        return sb.toString();

    }
}
